﻿@page "/posts/{pageindex?}"
@model Meowv.Blog.Web.Pages.Posts.IndexModel
@{
    ViewData["Title"] = "Posts - ";

    var response = Model.Posts;

    var posts = response.Result.Item;
    var total = (int)Math.Ceiling((response.Result.Total / (double)Model.PageSize));
}
<div class="post-wrap archive">
    @foreach (var item in posts)
    {
        <h3>@item.Year</h3>
        @foreach (var post in item.Posts)
        {
            <article class="archive-item">
                <a href="@("/post/" + post.Url)">@post.Title</a>
                <span class="archive-item-date">@post.CreatedAt</span>
            </article>
        }
    }
    <nav class="pagination">
        @for (int i = 1; i <= total; i++)
        {
            if (Model.PageIndex == i)
            {
                <span class="page-number current">@i</span>
            }
            else
            {
                <a class="page-number" href="/posts/@i">@i</a>
            }
        }
    </nav>
</div>